<?php
/**
 * 展示酒店公寓/小区,url重定向TODO 自定义URL
 *
 * @author Mike
 */
class HotelAction extends CommonAction {
    
    public function index(){
        $id = $_GET['id'];
        $hotel = $this->getHotelDetail($id);
        $this -> assign('hotel', $hotel);
        $map = array(
            'status' =>1,
            'hotel_id' => $id,
        );
        //$house['defaultPrice'] = $this->getDefaultPrice($id)
        $house = M('House')->where($map)->order('sort')->findAll();
        $this -> assign('house',$house);
        $this->assign('hotelList',M('Hotel')->where('status = 1 and id !='.$id)->order('sort')->getField('id,name'));
        
        $con = array(
            'status' => 1,//应该是approvedTODO,还是用status代替
            'pid' => $_GET['id'],
            'type' => 1,
        );
        $message = M('Comment') ->where($con)->order('create_time desc')->findAll();
        $this->assign('message', $message);
        $this->assign('bdmap',1);//展示百度地图
        //SEO
        $hotel_title = $hotel['name'].'-上海'.getConfigVal($hote['district'],'district').$hotel['address'].'酒店式公寓';
        $meta_title = empty($hotel['meta_title']) ? $hotel_title : $hotel['meta_title'];
        $this->assign('title',$meta_title);
        $meta_description = empty($hotel['meta_description']) ? cutstr( getDesc($hotel['around']),400 ) : $hotel['meta_description'];
        $this->assign('desc',$meta_description );
        $this->assign('keywords',$hotel['meta_keywords']);

        $this->display();
    }

        /**
     *获取单个公寓的详细信息
     * @param <type> $id hotel id
     */
    public function getHotelDetail($id){
        $map = array(
            'status' => 1,
            'id' => intval($id),
        );
        $data = M('Hotel')->where($map)->find();
        if(is_array($data) ){
            $data['logo'] = A('Hotel')->get_picture($id,'hotel',2);
            $data['pic'] = A('Hotel')->get_picture($id,'hotel',1); //得到所有的附属图片
        }
        return $data;
    }

    public function listing(){
        //TODO暂不分页
        $district = $_GET['id'];
        $map = array(
            'status' =>1,
            'district' => intval($district),
            'attachfunc'=> 2,//logo必须上传，否则不能显示 加上这个避免重复数据出现
        );
        $hotels = D('HotelView')->where($map)->field('id,name,address,traffic,url')->findAll();
        if(empty ($hotels)){
            $this->assign('jumpUrl',__APP__.'/');
            $this->error('您所查看的区域暂时无公寓！');
        }
        $this->assign('hotels',$hotels);
        //SEO
        $title = '上海'.getConfigVal($_REQUEST['id'],'district').'酒店式公寓出租,预订-月租公寓服务公寓租赁';
        $home_meta = M('Meta')->where('type="Hotel_listing" and tid='.$district)->find();
        $title = empty($home_meta['title']) ? $title : $home_meta['title'];
        $this->assign('title',$title);
        $desc = '上海好家服务公寓提供上海'.getConfigVal($_REQUEST['id'],'district').'高档酒店式公寓出租，直销经营，比同品质宾馆酒店便宜40%到50%，可洗衣做饭，家一样的温馨';
        $desc = empty($home_meta['description']) ? $desc : $home_meta['description'];
        $this->assign('desc',$desc);
        $this->assign('keywords',$home_meta['keywords']);

        $this->assign('hotelList',M('Hotel')->where('status = 1 ')->order('sort')->getField('id,name'));//推荐公寓
        $this->display();
    }
}
?>
